<?php




define('IN_ECS', true);

require (dirname(__FILE__) . '/includes/init.php');

/* 载入语言文件 */
require_once (ROOT_PATH . 'languages/' . $_CFG['lang'] . '/user.php');

$user_id = $_SESSION['user_id'];
if (!$user_id)
{
	$Loaction = 'user.php';
	ecs_header("Location: $Loaction\n");
	exit;
}


$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('users'). " WHERE user_id = '$user_id'";
$row = $GLOBALS['db']->getRow($sql);
$smarty->assign('info', $row);

$action  =trim($_REQUEST['act']);

if($action=='sm'){

	$smarty->display('user_sm.dwt');	
}
elseif($action=='act_sm'){

	include_once(ROOT_PATH . '/includes/cls_image.php');	
	$image = new cls_image($_CFG['bgcolor']);
	$real_name= isset($_POST['real_name']) ? compile_str($_POST['real_name']) : '';	
	$card= isset($_POST['card']) ? compile_str($_POST['card']) : '';
	$card_img_sc = basename($image->upload_image($_FILES['card_img_sc'], 'user_img'));	
	
	$card_img_zm = basename($image->upload_image($_FILES['card_img_zm'], 'user_img'));
	$card_img_fm = basename($image->upload_image($_FILES['card_img_fm'], 'user_img'));
	
	if(!$card_img_sc){
		$card_img_sc= isset($_POST['card_img_sc_val']) ? compile_str($_POST['card_img_sc_val']) : '';	
	}else{
		$img_file_sc=ROOT_PATH."/data/user_img/".$row['card_img_sc'];
		 unlink($img_file_sc);
	}
	if(!$card_img_zm){
		$card_img_zm= isset($_POST['card_img_zm_val']) ? compile_str($_POST['card_img_zm_val']) : '';
	}else{
		$img_file_zm=ROOT_PATH."/data/user_img/".$row['face_card'];
		 unlink($img_file_zm);
	}
	if(!$card_img_fm){
		$card_img_fm= isset($_POST['card_img_fm_val']) ? compile_str($_POST['card_img_fm_val']) : '';
	}else{
		$img_file_fm=ROOT_PATH."/data/user_img/".$row['back_card'];
		unlink($img_file_fm);
	}
	
	$sqluid = "SELECT status FROM " . $ecs->table('users') . " where user_id='$user_id'";
	$statusinfo= $db->getRow($sqluid);
	if($statusinfo['status']==1){
	    $status=1;
	}else{
	    $status=2;
	}

	$sql = 'UPDATE ' . $GLOBALS['ecs']->table('users') .
	" SET real_name = '" . $real_name . "', " .
	" card = '" . $card . "', " .
	" card_img_sc = '$card_img_sc'," .
	" status = '$status'," .
	" face_card = '$card_img_zm'," .
	" back_card = '$card_img_fm' ".
	"WHERE user_id = '$user_id'";
	$res=$GLOBALS['db']->query($sql);
	if($res){
		//$Loaction = 'user_dk.php?act=zy';
		//ecs_header("Location: $Loaction\n");
	    show_message("操作成功");
	}else{
		show_message("操作失败");
	}

	exit;
}




?>